﻿using System.Collections.Generic;
using BaseUtil;

public class CombinationConfigData : IXMLData
{
    public Dictionary<int, CombinationSuitInfo> combination_suit_info_map = new Dictionary<int, CombinationSuitInfo>();

    public override void WriteToBuf(NetOutStream outs)
    {
        XMLBuffHelper.WriteToBuf(combination_suit_info_map, outs);
    }

    public override void ReadFromBuf(NetInStream ins)
    {
        XMLBuffHelper.ReadFromBuf(ref combination_suit_info_map, ins);
    }
}

public class CombinationSuitInfo : IXMLData
{
    public List<int> m_badge_list = new List<int>();

    public int m_combin_type; //组合装类型

    //! 图标特效
    public string m_effect_src = "";

    //!对应表现
    public Dictionary<int, List<int>> m_feature_list = new Dictionary<int, List<int>>();

    //! 图标文件资源描述
    public string m_iconfile = "";

    public int m_id;

    //! 描述 
    public string m_intro = "";

    //!是否为高端服饰
    public bool m_is_advanced;

    //! 是否为限定
    public bool m_is_limit;

    //! 服饰等级
    public int m_item_level;
    public string m_name = "";

    public int m_sex;

    // 展示套装id
    public int m_show_suit_id;

    //! 展示图 
    public string m_showview = "";

    // 星级 
    public int m_star_level;


    public List<List<int>> m_suit_dress_list = new List<List<int>>();
    public Dictionary<int, CWearInfo> m_wear_info_map = new Dictionary<int, CWearInfo>();


    public List<List<int>> DressList
    {
        get { return m_suit_dress_list; }
    }

    public List<int> BadgeList
    {
        get { return m_badge_list; }
    }

    public bool IsAdvanced()
    {
        return m_is_advanced;
    }

    public bool IsDressingCombinationSuitByList(List<int> appearance_items)
    {
        if (appearance_items == null || appearance_items.Count == 0)
        {
            return false;
        }

        for (var i = 0; i < m_suit_dress_list.Count; i++)
        {
            var dressList = m_suit_dress_list[i];
            if (null == dressList)
            {
                continue;
            }

            for (var j = 0; j < dressList.Count; ++j)
            {
                var nItemTempID = dressList[j];
                if (0 == nItemTempID)
                {
                    continue;
                }

                // 只要avatarinfo中不包含部件列表中的任意一件.就认为没有穿齐该组合装.
                if (!appearance_items.Contains(nItemTempID))
                {
                    return false;
                }
            }
        }

        return true;
    }

    /// <summary>
    ///     默认获取第一个FeatureID.
    /// </summary>
    public int GetFeatureId(int state)
    {
        if (m_feature_list.ContainsKey(state))
        {
            if (m_feature_list[state].Count > 0)
            {
                return m_feature_list[state][0];
            }

            return 0;
        }

        return 0;
    }

    /// <summary>
    ///     根据徽章id，获取SuiteId
    /// </summary>
    /// <param name="badge_id">徽章id</param>
    /// <returns></returns>
    public int GetSuitIdByBadgeId(int badge_id)
    {
        if (m_badge_list.Exists(x => x == badge_id))
        {
            return m_id;
        }

        return 0;
    }

    public override void WriteToBuf(NetOutStream outs)
    {
        outs.Write(m_id);
        outs.Write(m_sex);
        outs.Write(m_star_level);
        outs.Write(m_name);
        outs.Write(m_iconfile);
        outs.Write(m_intro);
        outs.Write(m_showview);
        outs.Write(m_is_limit);
        outs.Write(m_effect_src);
        outs.Write(m_item_level);
        outs.Write(m_is_advanced);
        XMLBuffHelper.WriteToBuf(m_feature_list, outs);
        XMLBuffHelper.WriteToBuf(m_suit_dress_list, outs);
        XMLBuffHelper.WriteToBuf(m_badge_list, outs);
        outs.Write(m_show_suit_id);
        outs.Write(m_combin_type);
    }

    public override void ReadFromBuf(NetInStream ins)
    {
        ins.Read(ref m_id);
        ins.Read(ref m_sex);
        ins.Read(ref m_star_level);
        ins.Read(ref m_name);
        ins.Read(ref m_iconfile);
        ins.Read(ref m_intro);
        ins.Read(ref m_showview);
        ins.Read(ref m_is_limit);
        ins.Read(ref m_effect_src);
        ins.Read(ref m_item_level);
        ins.Read(ref m_is_advanced);
        XMLBuffHelper.ReadFromBuf(ref m_feature_list, ins);
        XMLBuffHelper.ReadFromBuf(ref m_suit_dress_list, ins);
        XMLBuffHelper.ReadFromBuf(ref m_badge_list, ins);
        ins.Read(ref m_show_suit_id);
        ins.Read(ref m_combin_type);
    }
}

public class CWearInfo : IXMLData
{
    public int m_nPieceNum;
    //public H3DDictionary<int, CollocationStyleBase> m_collocation_style_base_map = new H3DDictionary<int, CollocationStyleBase>();

    public override void WriteToBuf(NetOutStream outs)
    {
        outs.Write(m_nPieceNum);
    }

    public override void ReadFromBuf(NetInStream ins)
    {
        ins.Read(ref m_nPieceNum);
    }
}